/*
 * user.java
 *
 * Created on 14 Февраль 2008 г., 15:42
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package xmppbot.parse;

import xmppbot.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

/**
 *
 * @author lian
 */
public class user {
    String status = null;
    db DB = Main.Connect.mysqldb;
    ResultSet rs = null;
    HashMap perms = new HashMap();
    /** Creates a new instance of user */
    public user(String user) throws SQLException {
        try {
            rs = DB.getStatement().executeQuery("SELECT * FROM UserRoles WHERE id = (SELECT role FROM Users WHERE user = '" + utils.parseSymbols(user) + "');");
            rs.first();
            try {
                status = rs.getString("role");
            } catch (SQLException ex) {
                db.killrs(rs); rs = null;
                rs = DB.getStatement().executeQuery("SELECT * FROM UserRoles WHERE role = 'anonym';");
                rs.first();
                status = rs.getString("role");
            }
            int columns = rs.getMetaData().getColumnCount() - 2;
            for (int i = 1; i <= columns; i++)
            {               
                perms.put("_" + rs.getMetaData().getColumnName(2 + i), rs.getString(2 + i));
            }
            db.killrs(rs); rs = null;
        } catch (SQLException ex) {
            db.killrs(rs); rs = null;
        }
    }
    
}
